//app.js
App({
  onLaunch: function() {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    const that = this;
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId,sessionKey, unionId
        if (res.code) {
          wx.request({
            url: that.globalData.url + '/wechat/getOpenIdByCoach',
            data: 'code=' + res.code,
            method: 'POST',
            header: {
              'content-type': 'application/x-www-form-urlencoded',
            },
            success: function(response) {
              if (response.data.success) {
                const openId = response.data.content;
                const url = that.globalData.url;
                that.globalData.openId = openId;
                wx.request({
                  url: url + '/coach/check/' + openId,
                  method: "GET",
                  success: function(res) {
                    if (res.data.success == true) {
                      that.globalData.coachLogin = true;
                    }
                  }
                });
              } else {
                wx.showToast({
                  title: '获取OPENID失败,请重新进入小程序',
                  icon: 'none'
                })
              }
            }
          })
        }
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo;
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  globalData: {
    companyName:'先达健身',
    userInfo: null,
    openId: '',
    coachLogin:false,
    url: 'https://health.szcinda.cn/api',baseUrl: 'https://health.szcinda.cn',
    // url: 'http://localhost:8080/api',baseUrl: 'https://health.szcinda.cn',
    emsItems: [{
      position: '二头',
      columnName: 'ertou',
      checked: true
    }, {
      position: '背阔',
      columnName: 'beikuo',
      checked: true
    }, {
      position: '三头',
      columnName: 'santou',
      checked: true
    }, {
      position: '下背',
      columnName: 'xiabei',
      checked: true
    }, {
      position: '胸部',
      columnName: 'xiongbu',
      checked: true
    }, {
      position: '臀部',
      columnName: 'tunbu',
      checked: true
    }, {
      position: '腹部',
      columnName: 'fubu',
      checked: true
    }, {
      position: '前腿',
      columnName: 'qiantui',
      checked: true
    }, {
      position: '上背',
      columnName: 'shangbei',
      checked: true
    }, {
      position: '后腿',
      columnName: 'houtui',
      checked: true
    }],
    bodyMeasurements: [{
        name: '胸围',
        value: 0,
        columnName: 'xiongwei'
      },
      {
        name: '肩宽',
        value: 0,
        columnName: 'jiankuan'
      },
      {
        name: '左臂',
        value: 0,
        columnName: 'zuobi'
      },
      {
        name: '右臂',
        value: 0,
        columnName: 'youbi'
      },
      {
        name: '腰围',
        value: 0,
        columnName: 'yaowei'
      },
      {
        name: '臀围',
        value: 0,
        columnName: 'tunwei'
      },
      {
        name: '左大腿',
        value: 0,
        columnName: 'zuodatui'
      },
      {
        name: '右大腿',
        value: 0,
        columnName: 'youdatui'
      }
    ],
    positionTrains: [{
        name: '胸部训练',
        normal: ['胸部'],
        advance: ['胸部', '二头', '三头'],
        challenge: ['胸部', '二头', '三头', '腹部', '下背', '臀部', '前腿', '后腿'],
        movements: [
          '器械飞鸟', '悍马机推胸', '绳索推胸', '绳索飞鸟', '史密斯机卧推', '平板杠铃卧推', '上斜杠铃卧推', '下斜杠铃卧推', '俯卧撑/跪姿俯卧撑', '绳索上拉飞鸟'
        ]
      },
      {
        name: '背部训练',
        normal: ['上背', '背阔', '下背'],
        advance: ['上背', '背阔', '下背', '二头', '三头'],
        challenge: ['上背', '背阔', '下背', '二头', '三头', '腹部'],
        movements: [
          '俯身杠铃划船', '窄握高位下拉', '上斜哑铃划船', '器械辅助宽距引体向上', '引体向上', '俯身单臂长杠划船', '绳索反向飞鸟', '器械孤立划船', '直臂下拉', '单臂哑铃划船', '宽握高位下拉', 'V型把下拉'
        ]
      },
      {
        name: '手臂训练',
        normal: ['二头', '三头'],
        advance: ['二头', '三头', '腹部'],
        challenge: ['二头', '三头', '腹部', '下背'],
        movements: [
          '杠铃弯举', '哑铃弯举', '绳索锤式弯举', '平板凳臂屈伸', '绳索肱三头肌屈伸', '钻石俯卧撑', '牧师凳弯举', '仰卧杠铃肱三头肌屈伸', '器械牧师凳弯举', '仰卧哑铃肱三头肌屈伸', '过顶绳索弯举', 'EZ曲杠反响弯举', '双杠臂屈伸', '肱三头肌下压', '绳索弯举', '锤式弯举'
        ]
      },
      {
        name: '臀部训练',
        normal: ['臀部'],
        advance: ['臀部', '前腿', '后腿'],
        challenge: ['臀部', '前腿', '后腿', '腹部', '下背'],
        movements: [
          '大腿内收肌器械训练', '杠铃臀部推举', '绳索臀伸', '臀桥', '弹力带侧步走'
        ]
      },
      {
        name: '腹部训练',
        normal: ['腹部'],
        advance: ['腹部', '下背'],
        challenge: ['腹部', '下背', '臀部', '前腿', '后腿'],
        movements: [
          '器械卷腹', '健腹轮', '山羊挺身', '空蹬自行车', '波速球登山', '波速球平板支撑', '平板仰卧举腿', '膝板支撑', '俯身爬坡', '波速球平板摆腿', '波比跳', '登山', '卷腹', '平板支撑', '下斜仰卧起坐', '俯卧交替抬腿', '坐姿收腿', '俄罗斯转体', 'TRX爬山', '超人'
        ]
      },
      {
        name: '腿部训练',
        normal: ['前腿'],
        advance: ['前腿', '后腿'],
        challenge: ['腹部', '臀部', '前腿', '后腿'],
        movements: [
          '深蹲', '箭步蹲', '杠铃弓箭步', '杠铃深蹲', '波速球深蹲', '蛙跳', '俯卧腿弯举', '腿部推举', '哈克机深蹲', '坐姿腿弯举', '器械腿屈伸', '史密斯机深蹲', '相扑深蹲', 'TRX深蹲', '靠墙深蹲'
        ]
      },
      {
        name: '减脂训练',
        movements: [
          '敏捷梯训练', '战绳', '开合跳', '高抬腿', '波比跳', '壶铃', '药球扣球', 'TRX', '冲刺跑', '跳箱', '深蹲跳', '沙包深蹲', '跳绳', '滑橇推', '深蹲', '曲膝跳'
        ]
      }
    ]
  }
})